//
//  myTabBar.m
//  MangoTV
//
//  Created by apple  on 15-1-13.
//  Copyright (c) 2015年 apple . All rights reserved.
//

#import "myTabBar.h"
@interface myTabBar(){
    UIButton *btn;
}

@end


@implementation myTabBar
- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
    }
    
    return self;
}

- (void)setItems:(NSArray *)items
{
    CGFloat width = self.bounds.size.width / items.count;
    CGFloat height = self.bounds.size.height;
    
    for (int i = 0; i < items.count; i++) {
        UITabBarItem *item = items[i];
        
        btn = [UIButton buttonWithType:UIButtonTypeCustom];
        //[btn setTitle:item.title forState:UIControlStateNormal];
        [btn setImage:item.image forState:UIControlStateNormal];
        [btn setImage:item.selectedImage forState:UIControlStateSelected];
        [btn setImage:item.selectedImage forState:UIControlStateHighlighted];
        [btn addTarget:self action:@selector(didClicked:) forControlEvents:UIControlEventTouchUpInside];
        btn.frame = CGRectMake(width * i, 0, width, height);
        btn.tag = i;
        if (i == 0 ) {
            btn.selected = YES;

        }
        
        [self addSubview:btn];
    }
}

- (void)didClicked:(UIButton *)sender
{
    btn.selected = NO;
    sender.selected = YES;
    btn = sender;
    self.tabBarController.selectedIndex = sender.tag;
}



@end
